﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--开关主键-->
    <script src="/static/bootstrap/bootstrap-switch.js"></script>
    <link href="/static/bootstrap/bootstrap-switch.css" rel="stylesheet"/>

    <!--    配置select多选相关-->
    <script src="/static/layui/dist/xm-select.js"></script>


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
</head>
<body>

<style>
    html, body{background-color: #fff!important;}
    .new_main{border-top:1px solid #ccc}
    .batch{line-height:35px;}
    .layui-table-body .layui-table-cell {
        height:60px;
        line-height:60px;
    }
</style>

<div class="newtest">

    <div class="container new_serach">
        <span> 关键字：</span>
        <div class="layui-inline">
            <input class="form-control serach_key" name="keyword"  type="text">
        </div>
        <span> 状态：</span>
        <div class="layui-inline layui-form"  style="width:80px;">
            <select name="status" lay-filter="status">
                <option value="0" >全部</option>
                {volist name="batch" id="vo"}
                <option value="{$key}" >{$vo}</option>
                {/volist}
            </select>
        </div>
        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>
    </div>

    <div class="new_main">
        <table class="layui-hide" id="demo" lay-filter="demo"></table>

        <script type="text/html" id="barDemo">

            {{#  if(d.type === 1){ }}
                {{#  if(d.hairpintime === '未发卡'){ }}
                <a class="btn-sm btn-primary" lay-event="hairpin">发卡</a>
                {{#  } else { }}
                <a class="btn-sm btn-primary" href="{:URL('tickets/hairpin/detail')}?hairpin_id={{d.id}}" >查看发卡明细</a>
                {{# } }}

                {{#  if(d.status === 1){ }}
                <a class="btn-sm btn-danger" lay-event="cancellation">作废</a>
                {{# } }}
            {{#  } else { }}
                <a class="btn-sm btn-primary" href="{:URL('tickets/hairpin/detail')}?hairpin_id={{d.id}}" >查看发卡明细</a>
            {{# } }}





<!--            <a class="btn-sm btn-danger" lay-event="del">删除</a>-->
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a class="layui-btn-sm layui-btn" lay-event="add_btn">添加批次</a>
<!--                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">批量删除</button>-->
            </div>
        </script>

        <script type="text/html" id="switchTpl">
            <!--启用审核操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>


    </div>
</div>

<div class="modal fade" id="loading" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop='static' >
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">提示</h4>
            </div>
            <div class="modal-body">
                操作中，请勿进行其他操作。。。<span id="result"></span>
            </div>
        </div>
    </div>
</div>

</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<script>
    //全选操作
    var error = 0;
    var modal = new yii.modal();

    layui.use(['form', 'jquery', 'layer', 'laydate','table'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        var status = 0;
        form.on('select(status)',function (data) {
            status = data.value;
        });


        var classify_id = $('input[name="classify_id"]').val();
        var colony_id = $('input[name="colony_id"]').val();

        var url = "{:URL('tickets/hairpin/index')}";
        //搜索操作
        $('.layui-btn').click(function () {
            var keyword = $('input[name="keyword"]').val();
            var where = {keyword:keyword,status:status};
            search(table,url,where)
        });

        //列表
        var where = {type:'list'};
        var title = "门票列表";
        var cols = [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
            ,{field: 'sina', title: '批次校验', align:'center'}
            ,{field: 'count', title: '发布数量', align:'center'}
            ,{field: 'status_name', title: '状态',align:'center'}
            ,{field: 'type_name', title: '类型',align:'center'}
            ,{field: 'hairpintime', title: '发卡时间', align:'center',sort: true}
            ,{field: 'addtime', title: '添加时间', align:'center',sort: true}
            ,{fixed: 'right',title: '操作', width:300, align:'center', toolbar: '#barDemo'}
        ]];
        showlist(table,url,where,title,cols);

        //监听单元格编辑
        table.on('edit(demo)', function(obj){
            var value = obj.value; //得到修改后的值
            var id = obj.data.id;
            $.ajax({
                type: "post",
                url: "/common/Common/updateSort",
                data: {id: id,table:'admin_content',value:value},
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }
                }
            });
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            let url = "{:URL('common/together/clickStatus')}";

            if (state == true) {
                let data = {id:id,status:1,table:'tickets_hairpin',content:1}
                //上线
                publicClickStatus(url,data);
            } else {
                let data = {id:id,status:2,table:'tickets_hairpin',content:1}
                //下线
                publicClickStatus(url,data);
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj) {
            var id = obj.data.id;
            switch (obj.event) {
                case 'del':
                    layer.confirm('是否确定操作?', function (index) {
                        let url="{:URL('tickets/hairpin/delTickets')}";
                        let data = {id:id};
                        publicDel(table,url,data,obj,index);
                    });
                    break;
                case 'hairpin':
                    layer.confirm('进行该操作是请勿执行其他操作，是否确认该操作?', function (index) {
                        let data = {id:id};
                        if(error==1){
                            return false;
                        }
                        $('#loading').modal('show');
                        error = 1;
                        $.ajax({
                            type: 'post',
                            url: "{:URL('tickets/hairpin/hairpinApi')}",
                            data: data,
                            dataType: 'JSON',
                            success: function (res) {
                                layer.alert(res.msg);
                                if (res.code == 0) {
                                    $('#loading').modal('hide');
                                    error = 0;
                                    table.reload('demo');
                                }
                            },
                            error: function (res) {

                            }
                        });
                    });
                    break;
                case 'cancellation':
                    layer.confirm('该操作不可撤销，是否确定操作?', function (index) {
                        let data = {id:id,status:2};
                        if(error==1){
                            return false;
                        }
                        $('#loading').modal('show');
                        error = 1;
                        $.ajax({
                            type: 'post',
                            url: "{:URL('tickets/hairpin/cancellation')}",
                            data: data,
                            dataType: 'JSON',
                            success: function (res) {
                                layer.alert(res.msg);
                                if (res.code == 0) {
                                    $('#loading').modal('hide');
                                    error = 0;
                                    table.reload('demo');
                                }
                            },
                            error: function (res) {

                            }
                        });
                    });
                    break;

            }
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].id;
                    }
                    if(id.length==0){
                        layer.alert("请选择需操作的数据");return;
                    }
                    layer.confirm('是否确定操作?', function(index){
                        let url="{:URL('tickets/hairpin/delTickets')}";
                        let where = {id:id};
                        publicDel(table,url,where,obj,index,1);
                    });
                    break;
                case 'add_btn':
                    modal.initialization({
                        url: "{:URL('tickets/hairpin/addHairpin')}",
                        type: "post",
                        data:{
                            type:'detail'
                        }
                    });
                    break;

            };
        });



    });

</script>

</html>
